nition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    vector<int> largestValues(TreeNode* root) 
    {
        // 我们这里首先要进行一个层序遍历 
        // 首先要创建一个队列
        if (root == nullptr)
        {
            return {};
        }
        queue<TreeNode*> que;
        // 使用cur开始遍历 这个队列
        TreeNode* cur = root;
        que.push(cur);
        vector<vector<int>> vv;
        vector<int> v;
        int levelsize = 1;
        while (!que.empty())
        {
            if (levelsize) //!=0
            {
                cur = que.front();
                que.pop();
                levelsize--;
                v.push_back(cur->val);
                if (cur->left)
                {
                    que.push(cur->left);
                }
                if (cur->right)
                {
                    que.push(cur->right);
                }
            }
            else
            {
                levelsize = que.size();
                vv.push_back(v);
                v.clear();
            }
        }


        vector<int> ans;
        vv.push_back(v);
         for (auto x : vv)
         {
            int max = x[0];
            for (auto e : x)
            {
                if (e > max)
                {
                    max = e;
                }
            }
            ans.push_back(max);
         }

         return ans;
    }
};
